home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRCMPL.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  2KB  |  110 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ;
  9. ; strcmpl- Compares the string pointed at by es:si to the string following
  10. ;       the call instruction.
  11. ;
  12. ; inputs:
  13. ;
  14. ;    es:di-    First string (The string to compare)
  15. ;    cs:rtn-    Second string (The string to compare against)
  16. ;
  17. ;    e.g.,
  18. ;        "if (es:si < cs:rtn) then ..."
  19. ;
  20. ; returns: 
  21. ;
  22. ;    cx- index into strings where they differ (points at the zero byte
  23. ;        if the two strings are equal).
  24. ;    Condition codes set according to the string comparison.  You should
  25. ;    use the unsigned branches (ja, jb, je, etc.) after calling this
  26. ;    routine.
  27. ;
  28.         public    sl_strcmpl
  29. ;
  30. sl_strcmpl    proc    far
  31.         push    bp
  32.         mov    bp, sp
  33.         push    es
  34.         push    ds
  35.         push    cx
  36.         push    si
  37.         push    di
  38.         mov    ax, es
  39.         mov    ds, ax
  40.         mov    si, di
  41.         les    di, 2[bp]
  42. ;
  43. ; In order to preserve the direction flag across this call, we have to
  44. ; test whether or not it is set here and execute two completely separate
  45. ; pieces of code (so we know which state to exit in.  Unfortunately, we
  46. ; cannot use pushf to preserve this flag since we need to return status
  47. ; info in the other flags.
  48. ;
  49.         pushf
  50.         pop    ax
  51.         test    ah, 4        ;Test direction bit.
  52.         jnz    DirIsSet
  53. ;
  54. ; Compute the length of the string following the CALL instruction:
  55. ;
  56.         cld
  57.         mov    al, 0
  58.         mov    cx, 0ffffh
  59.     repne    scasb
  60.         xchg    di, 2[bp]    ;Save as new return address.
  61.         neg    cx
  62.         dec    cx        ;Length of string.
  63.         mov    ax, cx
  64.         repe    cmpsb            ;Compare the two strings.
  65. ;
  66.         pushf
  67.         sub    ax, cx
  68.         dec    ax
  69.                 popf
  70.         pop    di
  71.         pop    si
  72.         pop    cx
  73.         pop    ds
  74.         pop    es
  75.         pop    bp
  76.         ret            ;Return with direction flag clear.
  77. ;
  78. ;
  79. DirIsSet:    cld
  80.         mov    al, 0
  81.         mov    cx, 0ffffh
  82.     repne    scasb
  83.         xchg    di, 2[bp]    ;Save as new return address.
  84.         neg    cx
  85.         dec    cx        ;Length of string.
  86.         mov    ax, cx
  87.         repe    cmpsb            ;Compare the two strings.
  88. ;
  89.         pushf
  90.         sub    ax, cx
  91.         dec    ax
  92.         popf
  93.         pop    di
  94.         pop    si
  95.         pop    cx
  96.         pop    ds
  97.         pop    es
  98.         pop    bp
  99.         std
  100.         ret            ;Return with direction flag set.
  101. ;
  102. ;
  103. ;
  104. sl_strcmpl    endp
  105. ;
  106. ;
  107. stdlib        ends
  108.         end
  109.